home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.teleport.com!usenet
- From: GHouck <hksys@teleport.com>
- Newsgroups: comp.lang.c
- Subject: Re: Can anyone HELP with variable delaration? Please?
- Date: 3 Apr 1996 12:38:53 GMT
- Organization: systems hk
- Message-ID: <4jtrgt$h77@nadine.teleport.com>
- References: <4jt07b$dul@news.us.net>
- NNTP-Posting-Host: ip-pdx01-07.teleport.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- sillybug@us.net (brian skrab) wrote:
- >Hello,
- >
- >I've just started learning C programming (moving up from Pascal) and I can't
- >seem to find an answer to this question. I'm sure this is going to sound
- >stupid, but how can I declare a variable to be of a data type string? Is
- >there a data type "string"?
- >
- Brian,
-
- A 'string' in C is typically an array of characters, or a pointer to
- a contiguous group of zero or more characters:
-
- char arrayOfChars[80]; /* array of 80 characters */
- char *ptrToChars; /* pointer to characters (which don't exist yet) */
- ...
- ptrToChars = (char *)malloc( 80 ); /* if successful, they do now (check for zero) */
- ...
- strcpy( arrayOfChars,"FirstName" );
- strcpy( ptrToChars,"LastName" );
- ...
-
- Yours, Geoff Houck
-
-